# Maintainer:

_realname=lib3mf
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
  "${MINGW_PACKAGE_PREFIX}-${_realname}-devel")
pkgver=1.8.1
pkgrel=1
pkgdesc='Lib3MF is the reference implementation of the 3D Manufacturing Format file standard http://3mf.io'
arch=('any')
url='https://github.com/3MFConsortium/lib3mf'
license=('BSD 2-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=(!staticlibs strip)
source=("${_realname}-${pkgver}.tar.gz"::"${url}/archive/v${pkgver}.tar.gz"
  install_component.patch)
sha256sums=('207dd142c9ca86a4fb1a4b2baadbdf579f35e03f9b8bf5c02dae027da5ae9d17'
            '6a241fa8fd4f378661fdd11e06797524ce84db2854c630cbfa279add716c6c64')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
	patch -Np1 -i "${srcdir}"/install_component.patch
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"
  
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DLIB3MF_TESTS=OFF \
    ../${_realname}-${pkgver}
}

eval "package_${MINGW_PACKAGE_PREFIX}-${_realname}() { package_${_realname}; }"
eval "package_${MINGW_PACKAGE_PREFIX}-${_realname}-devel() {
  depends=(\"\${MINGW_PACKAGE_PREFIX}-lib3mf\")
  package_${_realname}-devel; }"

package_lib3mf() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install_bin
}

package_lib3mf-devel() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install_devel
}
